import { Component, OnInit, Input, OnChanges } from '@angular/core';
import PanelInfoConfig from './panel-info';
import { NzModalService } from 'ng-zorro-antd';
import { OneMapService } from '../one-map.service';
import { DatePipe } from '@angular/common';
import { StadiaType } from '../one-map';

@Component({
  selector: 'app-panel-info',
  templateUrl: './panel-info.component.html',
  styleUrls: ['./panel-info.component.scss']
})
export class PanelInfoComponent implements OnChanges {
  @Input() data: any;
  infoConfig: any = {};
  irrAreaType: any = {
    1: "自流灌区",
    2: "扬水灌区"
  };
  IntakeType: any = {
    1: "地表水取水站",
    2: "地下水取水站",
    3: '退（排）水站'
  };
  stadiaType: any = StadiaType;
  monitorArr: string[] = ['jinshuizha', 'zhikaikou', 'db', 'dx', 'gy', 'ny', 'sh', 'hd', 'yz', 'hh', 'skswz', 'gqdm', 'shg', 'psg', 'ylz', 'sqz', 'cyylz', 'zygq', 'zypsg', 'zybz', 'zyzm', 'gyjc', 'nyjc', 'shjc', 'hhjc'];
  infoVisible: boolean = false;
  monitorVisible: boolean = false;
  nzFooter: any = null;
  monitorType: number;
  curDate: Date = new Date();
  params: any = {
    beginTime: this.datePipe.transform(new Date(+this.curDate - 14 * 24 * 60 * 60 * 1000), "yyyy-MM-dd"),
    endTime: this.datePipe.transform(this.curDate, "yyyy-MM-dd")
  };
  noInfoArr: string[] = ['kanghanjijing', 'shuichang', 'pumpsh', 'tiaoxuchi'];

  constructor(private mapService: OneMapService, private datePipe: DatePipe) { }

  ngOnChanges(): void {
    console.log(this.data);
    const layer = this.data.layer;
    this.data.show = true;
    debugger
    this.infoConfig = PanelInfoConfig[layer] || {};
    this.getMonitorData();
  }

  getMonitorData() {
    // let monitorQuery;
    switch (this.data.layer) {
      case "bengzhan":
        // case "zybz":
        this.monitorType = 1;
        // monitorQuery = this.mapService.getProcessListPump({
        //   ...this.params,
        //   stadiaCode: this.data.code || this.data.stadiaCode
        // });
        break;
      case "zybz":
        this.monitorType = 6;
        // monitorQuery = this.mapService.getProcessListPump({
        //   ...this.params,
        //   stadiaCode: this.data.code || this.data.pumpCode
        // });
        break;
      case "jinshuizha":
      case "jiezhizha":
      case "tuishuizha":
      case "zhikaikou":
        this.monitorType = 2;
        // monitorQuery = this.mapService.getProcessListGate({
        //   ...this.params,
        //   stadiaCode: this.data.code
        // });
        break;
      case "zyzm":
        this.monitorType = 5;
        // monitorQuery = this.mapService.getProcessListGate({
        //   ...this.params,
        //   stadiaCode: this.data.code || this.data.strobeCode
        // });
        break;
      case 'db': // 地表取水口
      case 'dx': // 地下取水口
      case 'gy': // 工业取水口
      case 'ny': // 农业取水口
      case 'sh': // 生活取水口
        this.monitorType = 3;
        this.mapService.queryQSK({
          ...this.params,
          wiustCd: this.data.wiust_cd || this.data.wiu_cd
        }).subscribe(res => {
          if (res.dayW && res.dayW.length) {
            this.data.dayW = res.dayW[res.dayW.length - 1].dayW;
          }
          if (res.mpQ && res.mpQ.length) {
            this.data.mpQ = res.mpQ[res.mpQ.length - 1].mpQ;
          }
        });
        break;
      case 'hd': // 河道水文站
      case 'yz': // 堰闸水文站
      case 'hh': // 黄河断面
      case 'skswz': // 水库水文站
      case 'gqdm': // 干渠断面
      case 'shg': // 山洪沟断面
      case 'psg': // 排水沟断面
      case 'ylz': // 雨量站
      case 'sqz': // 墒情站
      case 'cyylz': // 雨量站
      case 'zygq': // 干渠断面
      case 'zypsg': // 排水沟断面
        this.monitorType = 4;
        this.getProcessListSection().subscribe(res => {
          if (res.list && res.list.length) {
            this.data = {
              ...res.list[res.list.length - 1],
              ...this.data
            };
          } else if (res && res.length) {
            this.data = {
              ...res[res.length - 1],
              ...this.data
            };
          }
        });
        break;
      case 'gyjc': // 工业取水口
      case 'nyjc': // 农业取水口
      case 'shjc': // 生活取水口
      case 'hhjc': // 混合取水口
        this.monitorType = 3;
        this.mapService.queryProcessIntake({
          ...this.params,
          wiuCd: this.data.wiuCd || this.data.wiu_cd
        }).subscribe((res: any) => {
          if (res.dayW && res.dayW.length) {
            this.data.dayW = res.dayW[res.dayW.length - 1].dayW;
          }
          if (res.mpQ && res.mpQ.length) {
            this.data.mpQ = res.mpQ[res.mpQ.length - 1].mpQ;
          }
        });
        break;
    }
  }

  getProcessListSection() {
    const params = {
      ...this.params,
      stadiaCode: this.data.stadiaCode
    };
    switch (this.data.layer) {
      case 'hd':
      case 'yz':
        return this.mapService.queryHDDM(params);
      case 'hh':
        if (this.data.stadiaType == 7) {
          return this.mapService.queryHDDM(params);
        } else {
          return this.mapService.queryHDDMSK(params);
        }
      case 'skswz':
        return this.mapService.querySKSWZ(params);
      case 'gqdm':
      case 'zygq':
        return this.mapService.queryGQDM(params);
      case 'shg':
        return this.mapService.querySHGDM(params);
      case 'psg':
      case 'zypsg':
        return this.mapService.queryPSGDM(params);
      case 'ylz': // 雨量站
      case 'cyylz': // 雨量站
        return this.mapService.queryYLZ(params);
      case 'sqz': // 墒情站
        return this.mapService.querySQZ(params);
    }
  }
}
